#include <stdio.h>

struct rational {
    int child, mother;
} Alias;

struct rational make_rational(int child, int mother) {
    struct rational result;
    result.child = child;
    result.mother = mother;
    return result;
}

struct rational rational_add(struct rational A, struct rational B) {
    struct rational result;
    int common;
    result.mother = A.mother * B.mother;
    result.child  = A.child * B.mother + B.child * A.mother;
    return result;
}

struct rational rational_sub(struct rational A, struct rational B) {
    struct rational result;
    int common;
    result.mother = A.mother * B.mother;
    result.child  = A.child * B.mother - B.child * A.mother;
    return result;
}

struct rational rational_mul(struct rational A, struct rational B) {
    struct rational result;
    int common;
    result.mother = A.mother * B.mother;
    result.child  = A.child * B.child;
    return result;
}

struct rational rational_div(struct rational A, struct rational B) {
    struct rational result;
    int common;
    result.mother = A.mother * B.child;
    result.child  = A.child * B.mother;
    return result;
}

void print_rational(struct rational result) {
    printf("%d/%d\n", result.child, result.mother);
}

int euclid(int a, int b) {
    if ( a % b == 0 ) {
        return b;
    } else {
        return euclid(b, a % b);
    }
}
int main () {
    struct rational a, b, result;
    int common;
    a = make_rational(1, 8);
    b = make_rational(1, 4);
    result = rational_div(a, b);
    print_rational(result);
    common = euclid(result.mother, result.child);
    printf("common:%d\n", common);
    result.mother /= common;
    result.child  /= common;
    print_rational(result);
}
